# coding=utf-8
import os
import switch_control.telnetAPI
import time
import threading
import gpu_port_ip_map as Port_ip_map

def generate_bgp_spine(host_ip = '10.174.216.48'):
    # 生成bgp
    username = 'admin1234'
    password = 'Oxc_2012'
    changepwd = 'N'

    commit = 'commit'
    quit = 'q'
    sy = "system-view"
    admin = "admin"
    port_mode = "port-mode port"
    confirm = "Y"

    comm_list = []
    cmd1 = "bgp 1.2467"
    comm_list.append(cmd1)
    comm_list.append("commit")
    cmd2 = "router-id 3.3.3.3"
    comm_list.append(cmd2)
    comm_list.append("commit")
    for i in range(16):
        cmd3 = "peer 172.167.%s.1 as-number 1.2466"%(i+1)
        comm_list.append(cmd3)
        comm_list.append("commit")
    for i in range(16):
        cmd3 = "peer 172.167.%s.1 as-number 1.2465"%(i+1)
        comm_list.append(cmd3)
        comm_list.append("commit")
    for i in range(16):
        cmd3 = "peer 172.167.%s.1 enable"%(i+1)
        comm_list.append(cmd3)
        comm_list.append("commit")
        cmd3 = "peer 172.167.%s.1 advertise-community"%(i+1)
        comm_list.append(cmd3)
        comm_list.append("commit")
    for i in range(16):
        cmd3 = "peer 172.167.1.%s enable"%(i+1)
        comm_list.append(cmd3)
        comm_list.append("commit")
        cmd3 = "peer 172.167.1.%s advertise-community"%(i+1)
        comm_list.append(cmd3)
        comm_list.append("commit")

    for cmd in comm_list:
        print(cmd)

    # telnet_client = telnetAPI.TelnetClient()
    # if telnet_client.login_host(host_ip, username, password, changepwd):
    #     for cmd in comm_list:
    #         telnet_client.execute_some_command(cmd, interval=0.1)
    # else:
    #     print("fail")
    #     time.sleep(3)
# 171.10.10.1
def main():
    generate_bgp_spine('10.174.216.48')

if __name__ == "__main__":
    main()    
